/*
 *Copyright (c) 2008, Scendix Software, Inc.
 * 
 */
using System;

using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data; 
using Microsoft.MediaCenter.UI;
using System.Threading;
using System.Diagnostics;
using System.Globalization;
using Microsoft.Win32;

namespace mceTapiRexv2
{
    public class Phonecall
    {
        private String dtCallDate;
        private String dtCallDuration;
        private Boolean bIncoming;
        private Boolean bAnswered;
        private Boolean bNew;
        private CallMember caller;
        private CallMember called;
   

        
        public Phonecall(DataRow dr)
        {
            DateTime callStart = (DateTime)dr[0];
            this.dtCallDate = callStart.ToString("g", Thread.CurrentThread.CurrentCulture.DateTimeFormat);
            if (dr[1].ToString() != "")
            {
                DateTime callEnd = (DateTime)dr[1];
                TimeSpan timespan = (TimeSpan)(callEnd - callStart);
                this.dtCallDuration = mceTapiRexv2.Application.Current.getResString("866",
                    new DateTime(timespan.Ticks).ToString("t", Thread.CurrentThread.CurrentCulture.DateTimeFormat), "");
            }
            // CallMember(string name, string id, string guid,bool isCaller)
            this.caller = new CallMember(dr[3].ToString(), dr[2].ToString(), dr[9].ToString(), true);
            this.called = new CallMember(dr[4].ToString(), dr[8].ToString(), dr[10].ToString(), false);
            this.bIncoming = (Boolean)dr[5];
            this.bAnswered = (Boolean)dr[6];
            this.bNew = (Boolean)dr[7];
        }
        public CallMember Caller
        {
            get { return caller; }
            set { caller = value; }
        }
        public CallMember Called
        {
            get { return called; }
            set { called = value; }
        }

        public String CallDate
            {
                get { return dtCallDate; }
                set { dtCallDate = value; }
            }
        public String CallDuration
            {
                get { return dtCallDuration; }
                set { dtCallDuration = value; }
            }
         public Boolean Incoming
        {
            get { return bIncoming; }
            set { bIncoming = value; }
        }
        public Boolean Answered
        {
            get { return bAnswered; }
            set { bAnswered = value; }
        }
        public Boolean New
        {
            get { return bNew; }
            set { bNew = value; }
        }
        public Image Thumbnail
        {
            get
            {
                if (bIncoming)
                    return Caller.Picture;
                else
                    return Called.Picture;
            }
            set { }
        }
    }
}
